import { Injectable } from '@angular/core';
//import {environment} from '../../environments/environment';
import * as JsEncryptModule from 'jsencrypt';
import {Md5} from "ts-md5";

@Injectable({
  providedIn: 'root'
})
export class EncryptService {

  private PUBLIC_KEY:string = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCeUi"
                + "MnlFGIxh5QnkkUG6ezXLZe9PRTU4pt7f1Gvpjqmg0d0Syciz/"
                + "e9PwZm0MvKNWXLS9eyIr0X9ntJgK1+41Cgj953jcHJcvHEQzR6fOaZWUqhej/"
                + "8YfJAC6O7Gt2TudjDETqIGIFc6/"
                + "rJuQmQCjVubwN9uumcJAkR4SuB+7GFQIDAQAB";

  constructor() { }

  rsaEcrypt(plaintext:string):string{
    let encrypt = new JsEncryptModule.JSEncrypt();
    encrypt.setPublicKey(this.PUBLIC_KEY);
    let ciphertext = encrypt.encrypt(plaintext);
    return ciphertext;
  }

  md5Ecrypt(plaintext:string):string{
    return Md5.hashStr(plaintext).toString();
  }
}
